package com.csthink.auditlog.dto;

import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonInclude;
import lombok.Getter;
import lombok.Setter;
import org.apache.commons.lang3.time.DateUtils;
import org.springframework.format.annotation.DateTimeFormat;

import javax.validation.constraints.Max;
import javax.validation.constraints.Min;
import java.util.Date;

/**
 * @author <a href="mailto:security.2009@live.cn">Mars</a>
 * @since 2023-09-12
 */
@Getter
@Setter
@JsonInclude(JsonInclude.Include.NON_NULL)
public class AuditLogQueryParamDTO {

    private String source;
    private String accountId;
    private String category;
    private String action;
    private String scrollId;
    private String keyword;
    private String operatorInfo;
    private String sortFiled;
    private String sortOrder;
    // Default last month
    @DateTimeFormat(pattern = "yyyy-MM-dd'T'HH:mm:ss.SSSZ")
    private Date from = DateUtils.addMonths(new Date(), -1);

    @DateTimeFormat(pattern = "yyyy-MM-dd'T'HH:mm:ss.SSSZ")
    private Date to = new Date();

    @Min(1)
    private int pageNumber = 1;

    @Max(100)
    @Min(10)
    private int pageSize = 10;

    @JsonIgnore
    @Override
    public String toString() {
        return String.format("Source: %s, Category: %s, Action: %s.", source, category, action);
    }
}
